package com.redis.service;

import java.util.List;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.redis.RedisFunction;
import com.report.entity.OnlineTerminal;

@Component
public class Onlineservice {

	@Value("${redis.host}")
	private String host;
	@Value("${redis.port}")
	private int port;

	public List<OnlineTerminal> getOnline(List<OnlineTerminal> onlineTerminals) {

		RedisFunction redisFunction = new RedisFunction(host, port);

		for (OnlineTerminal onlineTerminal : onlineTerminals) {
			Object object = redisFunction.GetKey(onlineTerminal.getTerminaladdress() + "online");
			if (object == null) {
				onlineTerminal.setStatus("0");
			} else {
				Object object1 = redisFunction.GetKey(onlineTerminal.getTerminaladdress() + "state");
				if (object1 == null) {
					onlineTerminal.setStatus("1");
				} else {
					onlineTerminal.setStatus("2");
				}
			}
		}

		return onlineTerminals;
	}

}
